import { BasicColumn, FormSchema } from '/@/components/Table';
import dayjs from 'dayjs';
import lodash from 'lodash';
import { h } from 'vue';
import { Tag } from 'ant-design-vue';
import { render } from '/@/utils/common/renderUtils';

export const columns: BasicColumn[] = [
  {
    title: '日志时间',
    align: 'center',
    dataIndex: 'timestamp',
    width: 180,
    customRender({ text }) {
      return dayjs(text).format('YYYY-MM-DD HH:mm:ss');
    },
  },
  {
    title: '日志信息',
    align: 'center',
    dataIndex: 'logMessage',
    ellipsis: true,
    customRender: ({ text }) =>  render.renderHtmlEllipsis(text,1),
  },
  {
    title: '请求级别',
    align: 'center',
    width: 80,
    dataIndex: 'logLevel',
    customRender: ({ text }) =>  render.renderHtmlEllipsis(text,1),
  },
  {
    title: '应用名',
    align: 'center',
    width: 120,
    dataIndex: 'appName',
    customRender: ({ text }) => render.renderHtmlEllipsis(text,1),
  },
  {
    title: '追踪ID',
    align: 'center',
    dataIndex: 'traceId',
    // customRender: ({ text }) => render.renderHtml(text),
    slots: { customRender: 'traceId' },
  },
  {
    title: 'spanId',
    align: 'center',
    dataIndex: 'spanId',
    customRender: ({ text }) => render.renderHtmlEllipsis(text,1),
  },
  {
    title: '类名',
    align: 'center',
    dataIndex: 'className',
    customRender: ({ text }) => render.renderHtmlEllipsis(text,1),
  },
  {
    title: '线程名',
    align: 'center',
    dataIndex: 'threadName',
    customRender: ({ text }) => render.renderHtmlEllipsis(text,1),
  },
  {
    title: '服务IP',
    align: 'center',
    width: 120,
    dataIndex: 'serverIp',
    customRender: ({ text }) => render.renderHtmlEllipsis(text,1),
  },
  {
    title: '服务端口',
    align: 'center',
    width: 80,
    dataIndex: 'serverPort',
    customRender: ({ text }) => render.renderHtmlEllipsis(text,1),
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'queryField',
    component: 'Select',
    label: '查询类型',
    defaultValue: '_all',
    componentProps: {
      options: [
        { value: '_all', label: '全文搜索' },
        { value: 'logMessage', label: '日志信息' },
        { value: 'logLevel', label: '日志级别' },
        { value: 'traceId', label: '链路追踪ID' },
        { value: 'appName', label: '应用名' },
        { value: 'className', label: '类名' },
      ],
    },
    colProps: {
      span: 6,
    },
  },
  {
    field: 'queryValue',
    label: '查询类型值',
    component: 'Input',
    colProps: { span: 6 },
  },
];

export const traceColumns: BasicColumn[] = [
  {
    title: '应用名',
    align: 'center',
    dataIndex: 'appName',
  },
  {
    title: 'spanId',
    align: 'center',
    dataIndex: 'spanId',
  },
  {
    title: '服务IP',
    align: 'center',
    dataIndex: 'serverIp',
  },
  {
    title: '服务端口',
    align: 'center',
    dataIndex: 'serverPort',
  },
];
